import G2 from '@antv/g2/dist/g2.min'
import { thousandBitSeparator } from '../utils'

export default {
  data () {
    return {
      chart: undefined
    }
  },
  methods: {
    /**
     * 绘制柱状图
     * @param data
     * @param dom
     * @param x
     * @param y
     * @param customer
     */
    drawColumn (data, dom, x, y, customer) {
      if (this.chart) {
        this.chart.destroy()
      }
      this.chart = new G2.Chart({
        container: dom,
        forceFit: true,
        height: 500,
        padding: [20, 20, 50, 20],
        renderer: 'svg'
      })
      this.chart.scale(y, {
        formatter: function (x) {
          return x ? thousandBitSeparator(x) : x
        }
      })
      this.chart.tooltip({
        showTitle: false
      })
      this.chart.source(data)
      if (customer) {

      } else {
        this.chart.interval().position(`${x}*${y}`).tooltip(`${x}*${y}`, (name, value) => {
          return {
            name: name,
            value: thousandBitSeparator(value) + ' 篇'
          }
        })
      }
      this.chart.render()
    }
  }
}
